package com.ruoyi.web.controller.h5;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.apache.commons.codec.binary.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.H5User;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.UserShop;
import com.ruoyi.web.service.IUserShopService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品Controller
 * 
 * @author ruoyi
 * @date 2025-06-11
 */
@RestController
@RequestMapping("/h5/shop")
public class H5UserShopController extends BaseController
{
    @Autowired
    private IUserShopService userShopService;

    /**
     * 查询商品列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserShop userShop)
    {
        // startPage();
        List<UserShop> list = userShopService.selectUserShopList(userShop);
        return getDataTable(list);
    }

    /**
     * 获取商品详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userShopService.selectUserShopById(id));
    }

    /**
     * 新增商品
     */
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserShop userShop)
    {

        LoginUser loginUser = SecurityUtils.getLoginUser();
        H5User h5User = loginUser.getH5User();
        if(h5User.getTop().equals(0L)){
            userShop.setUserid(h5User.getId());
        }else{
            userShop.setUserid(h5User.getTop());
        }
        return toAjax(userShopService.insertUserShop(userShop));
    }

    /**
     * 修改商品
     */
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserShop userShop)
    {
        return toAjax(userShopService.updateUserShop(userShop));
    }

    /**
     * 删除商品
     */
    @Log(title = "商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userShopService.deleteUserShopByIds(ids));
    }
}
